import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import axios from 'axios'
//挂载axios
Vue.prototype.$http = axios
// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
//配置请求根路径
axios.defaults.baseURL = 'http://localhost:9000/demo'
//axios拦截器拦截每一个请求,有token就配置头信息的token
axios.interceptors.request.use(config => {
  let token = window.localStorage.getItem('authorization')
  if (token) {  // 判断是否存在token，如果存在的话，则每个http header都加上token
    config.headers.authorization = token
  }
  return config
}, error => {
  return Promise.reject(error)
})
//解决路径跳转的报错
import Router from 'vue-router'

const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
